package com.lagou.hot.controller;

import com.lagou.hot.cache.RedisService;
import com.lagou.hot.po.TJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisCluster;

import java.util.List;

@RestController
@EnableAutoConfiguration
@RequestMapping(value = "/job")
public class JobController {

    @Autowired
    private RedisService rs;

    @Autowired
    private JedisCluster jedisCluster;
    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping(value = "getredis")
    public List<TJob> getJobs() {
       return rs.getHotList();
    }

    @GetMapping("getKeyByJedisCluster")
    public String getKeyByJedisCluster(@RequestParam String key) {
        return jedisCluster.get(key);
    }

    @GetMapping("setKeyByJedisCluster")
    public void setKeyByJedisCluster(@RequestParam String key, @RequestParam String value) {
        jedisCluster.set(key, value);
    }

    @GetMapping("getKeyByRedisTemplate")
    public String getKeyByRedisTemplate(@RequestParam String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }

    @GetMapping("setKeyByRedisTemplate")
    public void setKeyByRedisTemplate(@RequestParam String key, @RequestParam String value) {
        redisTemplate.opsForValue().set(key,value);
    }
}
